# 面向对象编程（Object-Oriented Programming，OOP）
import types

# from lief.Object import Object


class Person(object):  #基类必须继承自object类，否则在派生类中无法使用super()函数

    num = 1

    def SayHello(self):
        print("Hello, I am Person.")

    def SayGoodbye(self):
        print("Goodbye, I am Person.")

    def __init__(self, name='', age=20,sex='male'):
        self.setName(name)
        self.setAge(age)
        self.setSex(sex)

    def PrintName(self):
        print("My name is", self.name)

    def PrintNum(self):
        print("My num is", self.num)

    def setName(self, name):
        if type(name) == str:
            self.name = name
        else:
            print("Name should be a string.")
    def setAge(self, age):
        if type(age) == int:
            self.age = age
        else:
            print("Age should be an integer.")
    def setSex(self, sex):
        if sex in ['male', 'female']:
            self.sex = sex
        else:
            print("Sex should be'male' or 'female'.")

    def show(self):
        print("Name:", self.name, "Age:", self.age, "Sex:", self.sex)

p1 = Person(" Alice ", 10)
p2 = Person(" Bob ", 20)
p1.SayHello()
p2.SayGoodbye()
p1.PrintName()
p2.PrintName()
p1.PrintNum()
p2.PrintNum()
print(p1.num)
print(p2.num)

class Student(Person):
    #调用基类构造方法初始化基类的私有数据成员
    def __init__(self, name='', age=20, sex='male', schoolyear=2006):
        super(Student, self).__init__(name, age, sex)
        self.schoolyear = schoolyear

    def setSchoolYear(self,schoolyear):
        if type(schoolyear) == int:
            self.schoolyear = schoolyear
        else:
            print("School year should be an integer.")
    def show(self):
        Person.show(self)
        print("School year:", self.schoolyear)
#主程序
if __name__ == '__main__':
    s1 = Student("Alice", 10, "female", 2010)
    s2 = Student("Bob", 20, "male", 2011)
    s1.SayHello()
    s2.SayGoodbye()
    s1.PrintName()
    s2.PrintName()
    s1.PrintNum()
    s2.PrintNum()
    s1.setSchoolYear(2012)
    s2.setSchoolYear(2013)
    s1.show()
    s2.show()
